﻿using mojoPortal.Business;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace blackhouse.mojoPortalExtend.Urls {
    public abstract class UrlSupport {

        #region Fields

        private string newUrl;

        #endregion

        #region Properties

        public string OldUrl { get; protected set; }
        public string NewUrl {
            get { return this.newUrl; }
            protected set { this.newUrl = FormatUrl(value); }
        }
        public string RealUrl { get; protected set; }
        public Guid Guid { get; protected set; }
        public FriendlyUrl FriendlyUrl { get; internal set; }
        public virtual int DirectSiteId { get { return 0; } }

        #endregion

        #region Methods

        public static string FormatUrl(string url) {
            // Url powinien mieć formę: ~/adres-strony
            // Możliwe wejścia to : /adres-strony
            // adres-strony
            url = url.ToLower();
            if (url.StartsWith("~/"))
                return url;
            if (url.StartsWith("/"))
                return '~' + url;
            return "~/" + url;
        }

        public abstract void ChangeToOtherNewUrl();
        public abstract void Save();

        #endregion

    }
}
